﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Data;
using ClassLibrary.Entity;

public partial class Admin_ListAccounts : AdminPage
{
    TblAccountsDAO AccountDAO = new TblAccountsDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadListAccount();
        }
    }

    private void LoadListAccount()
    {
        grdListAccount.DataSource = AccountDAO.GetAllAccounts();
        grdListAccount.DataBind();
    }
    protected void btnUpdate_Click(object sender, ImageClickEventArgs e)
    {
        int IDAcc = Convert.ToInt32(((ImageButton)sender).CommandArgument);
        //Response.Redirect("~/Admin/GetLayoutCode.aspx?idLayout=" + IDLayout);
        Response.Redirect("~/Admin/Account.aspx?IDAcc=" + IDAcc);
    }
    protected void btnReset_Click(object sender, ImageClickEventArgs e)
    {
        int IDAcc = Convert.ToInt32(((ImageButton)sender).CommandArgument);
        //Response.Redirect("~/Admin/GetLayoutCode.aspx?idLayout=" + IDLayout);
        //Response.Redirect("~/Admin/Account.aspx?IDAcc=" + IDAcc);
    }
    protected void grdListAccount_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            foreach (DataControlFieldCell cell in e.Row.Cells)
            {
                // check all cells in one row
                foreach (Control control in cell.Controls)
                {
                    ImageButton button = control as ImageButton;
                    if (button != null && button.CommandName == "Delete")
                    {
                        // Add delete confirmation
                        //button.CommandArgument = ((TblEmail)e.Row.DataItem).IDEmail.ToString();
                        button.OnClientClick = "if (!confirm('Do you want delete this User Guide?')) return false;";
                    }
                    if (button != null && button.CommandName == "save")
                    {
                        // Add delete confirmation
                        //button.CommandArgument = ((TblEmail)e.Row.DataItem).IDEmail.ToString();
                        button.OnClientClick = "if (!confirm('Bạn có muốn lưu không?')) return false;";
                    }
                }
            }
            Label lblTypeAcc = (Label)e.Row.Cells[3].FindControl("lblTypeAcc");
            string TypeAcc = DataBinder.Eval(e.Row.DataItem, "TypeAcc").ToString();
            bool Display = Convert.ToBoolean(DataBinder.Eval(e.Row.DataItem, "Display").ToString());
            Label lblDateExpiry = (Label)e.Row.Cells[4].FindControl("lblDateExpiry");
            lblDateExpiry.Text = Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "DateExpiry")).ToString("dd/MM/yyyy");
            if (TypeAcc == "2")
            {
                lblTypeAcc.Text = "FREE";
                lblTypeAcc.Style.Add("color", "Green");
                lblDateExpiry.Style.Add("color", "Green");
            }

            if (Display == false)
            {
                lblTypeAcc.Text = "Waiting become V.I.P";
                lblTypeAcc.Style.Add("color", "Black");
                lblDateExpiry.Style.Add("color", "Black");
            }
            else if (TypeAcc != "2" && Display == true)
            {
                lblTypeAcc.Text = "V.I.P";

                lblTypeAcc.Style.Add("color", "Red");
                lblDateExpiry.Style.Add("color", "Red");
            }
        }
    }
    protected void grdListAccount_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdListAccount.PageIndex = e.NewPageIndex;
        LoadListAccount();
    }
}
